<?php
/**
* @package Wh-Com
* @copyright Copyright (C) 2008 Jonas Brand. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
if( session_id() == '' ) session_start();
/*
* Funktion zur Pruefung eines mehrdimensionalen Arrays auf das Vorhandensein eines Wertes
* @param string $needle Zu suchender Wert
* @param array $heystack Zu durchsuchendes Array
*/
if(!function_exists('in_array_multi')) {
function in_array_multi($needle, $haystack)
{
    $found = false;
    if(is_array($haystack))
    foreach($haystack as $value)
        if((is_array($value) && in_array_multi($needle, $value)) || $value == $needle)
            $found = true;
    return $found;
} }

// loading module configuration
$pretext 				= $params->get( 'pretext' );
$posttext 				= $params->get( 'posttext' );
$tlds					= $params->get( 'tlds', 'eu,com,net,de,org' );
$free                   = $params->get( 'free' );
$registered             = $params->get( 'registered' );
$invalid                = $params->get( 'invalid' );
$registernow            = $params->get( 'registernow' );
$transfernow            = $params->get( 'transfernow' );
$submit                 = $params->get( 'submit' );

// loading component configuration
// get component id
$query = "SELECT a.id"
. "\n FROM #__components AS a"
. "\n WHERE ( a.admin_menu_link = 'option=com_webhosting' OR a.admin_menu_link = 'option=com_webhosting' )"
. "\n AND a.option = 'com_webhosting'"
;
$database->setQuery( $query );
$id = $database->loadResult();
// load the row from the db table
$row = new mosComponent( $database );
$row->load( $id );
if(!defined('LANGDIR')) define('LANGDIR',$mosConfig_absolute_path."/administrator/components/com_webhosting/language");
$lang=$mainframe->getCfg('lang');
if( file_exists( LANGDIR.'/params_'.$lang.'.xml' ) ) {
    $params = new mosParameters( $row->params, LANGDIR.'/params_'.$lang.'.xml', 'component' );
} else {
    $params = new mosParameters( $row->params, $mosConfig_absolute_path.'/administrator/components/com_webhosting/install.xml', 'component' );
}

$defaulttld				= $params->get( 'defaulttld', '');
$ignoredtlds				= $params->get( 'ignoredtlds', '');

// getting Itemid of webhosting component
$query = "SELECT id FROM #__menu WHERE componentid=".$id." LIMIT 1";
$database->setQuery( $query );
$Itemid = $database->loadResult();

/*
* Domainklasse laden
*/
include_once($mosConfig_absolute_path."/components/com_webhosting/domain.class.php");

// used for spoof hardening
$validate = josSpoofValue(1);
?>
<form action="" method="post" name="whcomwhois" >
<?php
if( trim($pretext) != '' )
    echo $pretext.'<br />';
?>

<input name="whcomwhois_domain" id="mod_whcomwhois_domainname" type="text" class="inputbox" alt="domainname" size="10" maxlength="63" />
<select name="whcomwhois_tld" size="1" class="inputbox">
<?php
$tlds=explode(",",$tlds);
foreach($tlds as $tld)
{
	$tld=trim($tld);
	if( $tld == trim($defaulttld) )
		echo '<option value="'.$tld.'" selected="yes">'.$tld.'</option>';
	else
		echo '<option value="'.$tld.'">'.$tld.'</option>';
}
?>
</select>

<input class="button" type="submit" value="<?php echo $submit ?>"/><br />

<?php
$domainname=trim(mosGetParam($_POST,'whcomwhois_domain')).".".mosGetParam($_POST,'whcomwhois_tld');
if($domainname !== '.') {
	$domain=new domain($domainname);
	if( $domain->is_valid() == false) {
		?>
		<span style="color: red; font-weight:bold;"><?php echo sprintf($invalid, $domainname) ?></span>
		<?php
	} else  {
		if( $domain->is_available() ) {
			?>
			<span style="color: green; font-weight:bold;"><?php echo sprintf($free, $domainname) ?></span><br />
			<a href="<?php echo sefRelToAbs( 'index.php?option=com_webhosting&Itemid='.$Itemid) ?>"><?php echo sprintf($registernow, $domainname) ?></a>
			<?php
		} else {
			?>
			<span style="color: red; font-weight:bold;"><?php echo sprintf($registered, $domainname) ?></span><br />
			<a href="<?php echo sefRelToAbs( 'index.php?option=com_webhosting&Itemid='.$Itemid) ?>"><?php echo sprintf($transfernow, $domainname) ?></a>
			<?php
		}
		
		unset($_SESSION['domains']);
		$_SESSION['domains'][0]['domain']=$domainname;
	}
}

if( trim($posttext) != '' )
    echo '<br />'.$posttext;
?>
</form>
<?php

?>